/*******************************************************************************
 ** Name: newint.cpp                                                          **
 ** Description: Definitions of the AMPs filesystem(s)                        **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James.                                **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (c) 2011-12 Open Design Strategies, LLC.

#define _MUNIX_NEWINT_CPP_ID "$Id$"
// Last Modified $DateTime$ by $Author$

#include "newint.h"

Integer24::Integer24(const uint32_t i)
{
    a[0] = (i);
    a[1] = (i>>8);
    a[2] = (i>>16);
}

Integer24 &
Integer24::operator += (const Integer24 & o)
{
    a[0] += o.a[0];
    a[1] += o.a[1];
    a[2] += o.a[2];
    return *this;
}

Integer24 &
Integer24::operator = (const Integer24 & o)
{
    a[0] = o.a[0];
    a[1] = o.a[1];
    a[2] = o.a[2];
    return *this;
}

const Integer24
Integer24::operator + (const Integer24 & o) const
{
    Integer24 res(A() + o.A());
    return res;
}

const Integer24
Integer24::operator - (const Integer24 & o) const
{
    Integer24 res(A() - o.A());
    return res;
}

const Integer24
Integer24::operator * (const Integer24 & o) const
{
    Integer24 res(A() * o.A());
    return res;
}

uint32_t
Integer24::A() const
{
    uint32_t n = (
        (uint32_t)(a[2]*0x10000)
    |   (uint32_t)(a[1]*0x100)
    |   (uint32_t)(a[0])
    );
    return n;
}
